package es.ats.codington.festival.junit;

import java.util.ArrayList;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import es.ats.codington.festival.daos.EventDAOImpl;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.Place.Real;
import es.ats.codington.festival.domain.Stadium;
import es.ats.codington.festival.domain.Place.Zone;
import es.ats.codington.festival.services.EventServiceImpl;
import es.ats.codington.festival.services.PlaceServiceImpl;

/**
 * The Class TEventDAO.
 */
public class TEventDAO extends TestCase {
	
	/** The stadium arcangel. */
	Stadium stadiumArcangel = new Stadium("Arcangel Stadium", "sport", true, "Arcangel", 25000, "Zone Shouth, Arcangel", Zone.south, Real.stadium);		
		
	/** The event match. */
	Event eventMatch = new Event(1, "Cordoba-madrid", "Match of football ,stage 23", 120, "sport", 25000, 1);
	
	/** The event match update. */
	Event eventMatchUpdate = new Event(6, "CCF-Betis", "Match of football ,stage 23", 120, "sport", 25000, 1);

	/**
	 * @see junit.framework.TestCase#setUp()
	 */
	@Before
	public void setUp() throws Exception {
		super.setUp();
		/*Stadium stadiumArcangel = new Stadium("Arcangel Stadium", "sport", true, "Arcangel", 25000, "Zone Shouth, Arcangel", Zone.south);		
		Event eventMatch = new Event(1, "Madrid-FCB", "Match of football ,stage 23", 120, "sport", 25000, 1);*/
	}

	/**
	 * @see junit.framework.TestCase#tearDown()
	 */
	@After
	public void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test insert event.
	 *
	 * @throws Exception the exception
	 */
	@Test
	public void testInsertEvent() throws Exception{
		
		PlaceServiceImpl placeS1 = new PlaceServiceImpl();
	//	boolean aux2 = placeS1.registerBuilding(stadiumArcangel);
		
		int aux;
		
		EventServiceImpl eventService = new EventServiceImpl();

		aux = eventService.insertEvent(eventMatch);

		try{
			assertEquals(1, aux);
	//		assertEquals(false, aux2);

		} catch(Exception ex){
			fail("No exception should be thrown");
		}
	}
	
	/**
	 * Test delete event.
	 *
	 * @throws Exception the exception
	 */
	@Test
	public void testDeleteEvent() throws Exception{
		
		EventServiceImpl eventService = new EventServiceImpl();
		
		int aux2 = eventService.deleteEvent(5);
		
		try{
			assertEquals(1, aux2);

		} catch(Exception ex){
			fail("No exception should be thrown");
		}	
	}
	
	/**
	 * Test update event.
	 *
	 * @throws Exception the exception
	 */
	@Test
	public void testUpdateEvent()throws Exception{
		
		EventServiceImpl eventService = new EventServiceImpl();
		
	//	EventDAOImpl e3 = new EventDAOImpl();
	//	int aux3 = e3.updateEventDAO(eventMatchUpdate);
		
		int aux3 = eventService.updateEvent(eventMatchUpdate);

		try{
			assertEquals(1, aux3);
		} catch(Exception ex){
			fail("No exception should be thrown");

		}
	}
	
	
	/**
	 * Test search event.
	 */
	@Test
	public void testSearchEvent(){

		EventServiceImpl eventService = new EventServiceImpl();

		Event event = new Event();
		
		event = eventService.searchEventbyID(2);	
	}
}
